<<<<<<< HEAD
goods = []
user_shop = []
new_l = []
s = 0
d_d = {}
while 1:
    print("""1.登录
2.注册""")
    nu = input(">>>")
    with open("密码本.txt", mode="r+", encoding="utf-8") as f:
        for i in f:
            d_d[i.split(":")[0].strip()] = i.split(":")[1].strip()
        if nu == "1" or nu == "登录":
            user_name = input("请输入你的账号:")
            password = input("请输入你的密码:")
            if d_d[user_name] == password:
                print("登陆成功")
                break
            else:
                print("账号或密码错误")
                continue
        elif nu == "2" or nu == "注册":
            user_name = input("请输入你的账号:")
            if user_name in d_d.keys():
                print("账号已存在")
                continue
            else:
                password = input("请输入你的密码")
                f.write(f"""\n{user_name}:{password}""")
                continue
while 1:
    money = input("请充值:")
    if money.isdecimal():
        money = int(money)
        break
    else:
        print("充值错误,请重新充值")
        continue
with open("shopping.txt", mode="r", encoding="utf-8") as f,\
        open("购买记录.txt", mode="a", encoding="utf-8") as f1:
    l1 = f.readline().split()
    for i in f:
        l2 = i.split()
        dic = {}
        for em in range(len(l2)):
            dic[l1[em]] = l2[em]
        goods.append(dic)
    while 1:
        for num, el in enumerate(goods, 1):
            print(num, el["name"], el["price"])
        print("输入n结算,输入q退出,输入序号选择商品")
        user_choice = input("请输入你的选择:")
        if user_choice.upper() == "Q":
            if s == 0:
                print("您还未进行结算")
                continue
            else:
                break
        else:
            if user_choice.upper() == "N":
                s = 0
                for u_i in user_shop:
                    s += int(u_i["price"])
                while s > money:
                    print("金额不足,请删除商品")
                    de = input("请输入要删除的商品")
                    nd = goods[int(de) - 1]["name"]
                    for i in user_shop:
                        if nd in i.keys():
                            new_l.append(i)
                    for em in new_l:
                        user_shop.remove(em)
                    s = 0
                    for u_i in user_shop:
                        s += int(u_i["price"])
                else:
                    print("可以直接购买")
            elif user_choice.isdecimal():
                if int(user_choice) in range(1, len(goods) + 1):
                    a = goods[int(user_choice) - 1]["name"]
                    b = goods[int(user_choice) - 1]["price"]
                    print(a, b)
                    dic_u = {}
                    dic_u[a] = dic_u.get(a, 0) + 1
                    dic_u["price"] = b
                    user_shop.append(dic_u)
                    print(user_shop)
                else:
                    print("输入序号超出范围,请重新输入")
                    continue
            else:
                print("输入有误,请重新输入")
                continue
    print(f"""您购买的物品清单{user_shop},一共消费{s}元,您的账户剩余{money-s}元""")
    f1.write(f"""您购买的物品清单{user_shop},一共消费{s}元,您的账户剩余{money-s}元\n""")













=======
goods = []
user_shop = []
new_l = []
s = 0
d_d = {}
while 1:
    print("""1.登录
2.注册""")
    nu = input(">>>")
    with open("密码本.txt", mode="r+", encoding="utf-8") as f:
        for i in f:
            d_d[i.split(":")[0].strip()] = i.split(":")[1].strip()
        if nu == "1" or nu == "登录":
            user_name = input("请输入你的账号:")
            password = input("请输入你的密码:")
            if d_d[user_name] == password:
                print("登陆成功")
                break
            else:
                print("账号或密码错误")
                continue
        elif nu == "2" or nu == "注册":
            user_name = input("请输入你的账号:")
            if user_name in d_d.keys():
                print("账号已存在")
                continue
            else:
                password = input("请输入你的密码")
                f.write(f"""\n{user_name}:{password}""")
                continue
while 1:
    money = input("请充值:")
    if money.isdecimal():
        money = int(money)
        break
    else:
        print("充值错误,请重新充值")
        continue
with open("shopping.txt", mode="r", encoding="utf-8") as f,\
        open("购买记录.txt", mode="a", encoding="utf-8") as f1:
    l1 = f.readline().split()
    for i in f:
        l2 = i.split()
        dic = {}
        for em in range(len(l2)):
            dic[l1[em]] = l2[em]
        goods.append(dic)
    while 1:
        for num, el in enumerate(goods, 1):
            print(num, el["name"], el["price"])
        print("输入n结算,输入q退出,输入序号选择商品")
        user_choice = input("请输入你的选择:")
        if user_choice.upper() == "Q":
            if s == 0:
                print("您还未进行结算")
                continue
            else:
                break
        else:
            if user_choice.upper() == "N":
                s = 0
                for u_i in user_shop:
                    s += int(u_i["price"])
                while s > money:
                    print("金额不足,请删除商品")
                    de = input("请输入要删除的商品")
                    nd = goods[int(de) - 1]["name"]
                    for i in user_shop:
                        if nd in i.keys():
                            new_l.append(i)
                    for em in new_l:
                        user_shop.remove(em)
                    s = 0
                    for u_i in user_shop:
                        s += int(u_i["price"])
                else:
                    print("可以直接购买")
            elif user_choice.isdecimal():
                if int(user_choice) in range(1, len(goods) + 1):
                    a = goods[int(user_choice) - 1]["name"]
                    b = goods[int(user_choice) - 1]["price"]
                    print(a, b)
                    dic_u = {}
                    dic_u[a] = dic_u.get(a, 0) + 1
                    dic_u["price"] = b
                    user_shop.append(dic_u)
                    print(user_shop)
                else:
                    print("输入序号超出范围,请重新输入")
                    continue
            else:
                print("输入有误,请重新输入")
                continue
    print(f"""您购买的物品清单{user_shop},一共消费{s}元,您的账户剩余{money-s}元""")
    f1.write(f"""您购买的物品清单{user_shop},一共消费{s}元,您的账户剩余{money-s}元\n""")













>>>>>>> 00
